home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 125
/
Freelog_MarsAvril2015_No125.iso
/
Musique
/
Quod Libet
/
quodlibet-3.3.0-installer.exe
/
bin
/
quodlibet
/
qltk
/
window.pyc
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2014-12-31
|
13KB
|
306 lines
# Source Generated with Decompyle++
# File: in.pyc (Python 2.7)
import sys
import os
from gi.repository import Gtk, GObject, Gdk
from quodlibet import config
from quodlibet.qltk import get_top_parent, is_wayland
from quodlibet.util import DeferredSignal
from quodlibet.util import connect_obj
def should_use_header_bar():
settings = Gtk.Settings.get_default()
if not settings:
return False
if not None(settings.props, 'gtk_dialogs_use_header'):
return False
return None.get_property('gtk-dialogs-use-header')
class Dialog(Gtk.Dialog):
"""A Gtk.Dialog subclass which supports the use_header_bar property
for all Gtk versions and will ignore it if header bars shouldn't be
used according to GtkSettings.
"""
def __init__(self, *args, **kwargs):
if not should_use_header_bar():
kwargs.pop('use_header_bar', None)
super(Dialog, self).__init__(*args, **kwargs)
class Window(Gtk.Window):
'''Base window class the keeps track of all window instances.
All active instances can be accessed through Window.windows.
By defining dialog=True as a kwarg binds Escape to close, otherwise
^W will close the window.
'''
windows = []
_preven_inital_show = False
__gsignals__ = {
'close-accel': (GObject.SIGNAL_RUN_LAST | GObject.SIGNAL_ACTION, GObject.TYPE_NONE, ()) }
def __init__(self, *args, **kwargs):
self._header_bar = None
dialog = kwargs.pop('dialog', True)
super(Window, self).__init__(*args, **kwargs)
type(self).windows.append(self)
self._Window__accels = Gtk.AccelGroup()
if dialog:
self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
self.set_destroy_with_parent(True)
self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
self.add_accel_group(self._Window__accels)
if not dialog:
self.add_accelerator('close-accel', self._Window__accels, ord('w'), Gdk.ModifierType.CONTROL_MASK, 0)
else:
(esc, mod) = Gtk.accelerator_parse('Escape')
self.add_accelerator('close-accel', self._Window__accels, esc, mod, 0)
connect_obj(self, 'destroy', type(self).windows.remove, self)
def set_default_size(self, width, height):
if self._header_bar:
if width != -1:
width += min(width - 174, 56)
if height != -1:
height += 84
super(Window, self).set_default_size(width, height)
def use_header_bar(self):
'''Try to use a headerbar, returns the widget or None in case
GTK+ is too old or headerbars are disabled (under xfce for example)
'''
if not not (self._header_bar):
raise AssertionError
if not None():
return False
header_bar = None.HeaderBar()
header_bar.set_show_close_button(True)
header_bar.show()
old_title = self.get_title()
self.set_titlebar(header_bar)
if old_title is not None:
self.set_title(old_title)
self._header_bar = header_bar
self.set_default_size(*self.get_default_size())
return header_bar
def has_close_button(self):
'''Returns True in case we are sure that the window decorations include
a close button.
'''
if self.get_type_hint() == Gdk.WindowTypeHint.NORMAL:
return True
if None.name == 'nt':
return True
if None.platform == 'darwin':
return True
if None._header_bar is not None:
return self._header_bar.get_show_close_button()
def present(self):
'''A version of present that also works if not called from an event
handler (there is no active input event).
See https://bugzilla.gnome.org/show_bug.cgi?id=688830
'''
try:
GdkX11 = GdkX11
import gi.repository
except ImportError:
super(Window, self).present()
window = self.get_window()
if window:
timestamp = GdkX11.x11_get_server_time(window)
self.present_with_time(timestamp)
else:
super(Window, self).present()
def set_transient_for(self, parent):
'''Set a parent for the window.
In case parent=None, fall back to the main window.
'''
if parent:
pass
is_toplevel = parent.props.type == Gtk.WindowType.TOPLEVEL
if parent is None or not is_toplevel:
if parent:
print_w('Not a toplevel window set for: %r' % self)
app = app
import quodlibet
parent = app.window
super(Window, self).set_transient_for(parent)
def do_close_accel(self):
if isinstance(self.get_focus(), Gtk.Entry) and isinstance(self.get_focus().get_parent(), Gtk.TreeView):
self.get_focus().get_parent().grab_focus()
return None
if not None.emit('delete-event', Gdk.Event.new(Gdk.EventType.DELETE)):
self.destroy()
def prevent_inital_show(cls, value):
cls._preven_inital_show = bool(value)
prevent_inital_show = classmethod(prevent_inital_show)
def show_maybe(self):
'''Show the window, except if prevent_inital_show() was called and
this is the first time
'''
if not self._preven_inital_show:
self.show()
class PersistentWindowMixin(object):
'''A mixin for saving/restoring window size/position/maximized state'''
def enable_window_tracking(self, config_prefix, size_suffix = ''):
'''Enable tracking/saving of changes and restore size/pos/maximized
config_prefix -- prefix for the config key
(prefix_size, prefix_position, prefix_maximized)
size_suffix -- optional suffix for saving the size. For cases where the
window has multiple states with different content sizes.
(example: edit tags with one song or multiple)
'''
self._PersistentWindowMixin__state = 0
self._PersistentWindowMixin__name = config_prefix
self._PersistentWindowMixin__size_suffix = size_suffix
self._PersistentWindowMixin__save_size_deferred = DeferredSignal(self._PersistentWindowMixin__do_save_size, timeout = 50, owner = self)
self.connect('configure-event', self._PersistentWindowMixin__configure_event)
self.connect('window-state-event', self._PersistentWindowMixin__window_state_changed)
self.connect('notify::visible', self._PersistentWindowMixin__visible_changed)
self._PersistentWindowMixin__restore_window_state()
def __visible_changed(self, *args):
if not self.get_visible():
self._PersistentWindowMixin__restore_window_state()
def __restore_window_state(self):
if not is_wayland():
self._PersistentWindowMixin__restore_state()
self._PersistentWindowMixin__restore_position()
self._PersistentWindowMixin__restore_size()
def __conf(self, name):
if name == 'size':
name += '_' + self._PersistentWindowMixin__size_suffix
return '%s_%s' % (self._PersistentWindowMixin__name, name)
def __restore_state(self):
print_d('Restore state')
if config.getint('memory', self._PersistentWindowMixin__conf('maximized'), 0):
self.maximize()
else:
self.unmaximize()
def __restore_position(self):
print_d('Restore position')
pos = config.get('memory', self._PersistentWindowMixin__conf('position'), '-1 -1')
(x, y) = map(int, pos.split())
if x >= 0 and y >= 0:
self.move(x, y)
def __restore_size(self):
print_d('Restore size')
value = config.get('memory', self._PersistentWindowMixin__conf('size'), '-1 -1')
(x, y) = map(int, value.split())
screen = self.get_screen()
x = min(x, screen.get_width())
y = min(y, screen.get_height())
if x >= 1 and y >= 1:
self.resize(x, y)
def __configure_event(self, window, event):
self._PersistentWindowMixin__save_size_deferred(event.width, event.height)
return False
def __do_save_size(self, width, height):
if self._PersistentWindowMixin__state & Gdk.WindowState.MAXIMIZED:
return None
value = None % (width, height)
config.set('memory', self._PersistentWindowMixin__conf('size'), value)
if self.get_property('visible'):
pos_value = '%s %s' % self.get_position()
config.set('memory', self._PersistentWindowMixin__conf('position'), pos_value)
def __window_state_changed(self, window, event):
self._PersistentWindowMixin__state = event.new_window_state
if self._PersistentWindowMixin__state & Gdk.WindowState.WITHDRAWN:
return None
maximized = None(self._PersistentWindowMixin__state & Gdk.WindowState.MAXIMIZED)
config.set('memory', self._PersistentWindowMixin__conf('maximized'), maximized)
class _Unique(object):
'''A mixin for the window class to get a one instance per class window.
The is_not_unique method will return True if the window
is already there.
'''
_Unique__window = None
def __new__(klass, *args, **kwargs):
window = klass._Unique__window
if window is None:
return super(_Unique, klass).__new__(klass, *args, **kwargs)
widgets = None((lambda x: isinstance(x, Gtk.Widget)), args)
if widgets:
parent = window.get_transient_for()
new_parent = get_top_parent(widgets[0])
if parent and new_parent and parent is not new_parent:
window.set_transient_for(new_parent)
window.hide()
window.show()
window.present()
return window
def is_not_unique(klass):
return bool(klass._Unique__window)
is_not_unique = classmethod(is_not_unique)
def __init__(self, *args, **kwargs):
if type(self)._Unique__window:
return None
type(self)._Unique__window = None
super(_Unique, self).__init__(*args, **kwargs)
connect_obj(self, 'destroy', self._Unique__destroy, self)
def _Unique__destroy(self, *args):
type(self)._Unique__window = None
class UniqueWindow(_Unique, Window):
pass